import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/utils/utils.dart';

import 'package:ball_lion/entity/record/football/zq_transfer_entity.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/resources/styles.dart';
import 'package:ball_lion/utils/date_time_utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'package:ball_lion/widgets/base/wqs_bottomsheet.dart';

class ZqTransferCard extends StatelessWidget {
  final Transfers transfer;
  ZqTransferCard(this.transfer, {super.key});

  static show(Transfers transfer) {
    // Get.bottomSheet(QsBottomSheet(child: ZqTransferCard(transfer)),
    //     isScrollControlled: true);
  }

  @override
  Widget build(BuildContext context) {
    List<String> info = [];
    if (transfer.countryCn.hasValue) {
      info.add(transfer.countryCn!);
    }
    if (transfer.positionCn.hasValue) {
      info.add(transfer.positionCn!);
    }
    if (transfer.age != null || transfer.age != 0) {
      info.add('${transfer.age!.toString()}岁');
    }
    if (transfer.height!.hasValue) {
      info.add('${(double.parse(transfer.height!) / 100).toStringAsFixed(2)}米');
    }
    if (transfer.weight!.hasValue) {
      info.add('${transfer.weight!}公斤');
    }
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        CachedNetworkImage(
          height: 50,
          width: 50,
          fit: BoxFit.fitWidth,
          imageUrl: transfer.photo ?? '',
          placeholder: (context, url) => Styles.placeholderIcon(),
          errorWidget: (context, url, error) => Image.asset(
            Utils.getImgPath('zq_placeholder.png'),
            // height: 24,
            // width: 24,
          ),
        ),
        SizedBox(height: 14),
        QsText(transfer.nameChs ?? '',
            fontSize: 15, fontWeight: FontWeight.w500),
        SizedBox(height: 4),
        QsText(transfer.nameEn ?? '', fontSize: 12, color: Colours.grey66),
        SizedBox(height: 4),
        QsText(info.join('/'), fontSize: 12, color: Colours.grey66),
        SizedBox(height: 30),
        _item(
            '转会时间',
            DateTimeUtils.formatTimeStamp(
                transfer.transferTime!, 'yyyy-MM-dd')),
        _item('转会类型', transfer.transferTypeCn ?? '不详'),
        _item('转会价格', transfer.money.hasValue ? '${transfer.money}万英镑' : '不详'),
        _item('转会球队', '由${transfer.fromTeamCn}转会至${transfer.toTeamCn}'),
        if (transfer.endTime.hasValue)
          _item('合同到期',
              DateTimeUtils.formatTimeStamp(transfer.endTime!, 'yyyy-MM-dd')),
        const SizedBox(height: 50),
      ],
    );
  }

  _item(String title, String detail) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 10, left: 14),
      child: Row(children: [
        QsText(title, fontSize: 15, color: Colours.greyA9),
        const SizedBox(
          width: 28,
        ),
        Expanded(child: QsText(detail, fontSize: 15))
      ]),
    );
  }
}
